package com.virtualparadigm.compositor;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;

import com.virtualparadigm.identity.Identifiable;
import com.virtualparadigm.identity.ResourceIdentifier;

public abstract class ManyToOneCompositePart<CompositorType extends Identifiable> extends CompositePart<CompositorType> //implements Identifiable
{
	private static final long serialVersionUID = 1L;
	
	public ManyToOneCompositePart(ResourceIdentifier resourceIdentifier, OneToManyCompositorDelegate<CompositorType> oneToManyCompositorDelegate)
	{
		super(resourceIdentifier, oneToManyCompositorDelegate);
	}
	
	
//	// package protected
//	OneToManyCompositorDelegate<CompositorType> getOneToManyCompositorDelegate()
//	{
//		return (OneToManyCompositorDelegate<CompositorType>)this.getCompositorDelegate();
//	}
//	
	// package protected
	boolean setOneToManyCompositorDelegate(OneToManyCompositorDelegate<CompositorType> oneToManyCompositorDelegate)
	{
		return this.setCompositorDelegate(oneToManyCompositorDelegate);
	}
	 
//	public boolean setCompositor(CompositorType compositor)
//	{
////		return this.setOneToManyCompositorDelegate(compositor.);
////		return this.setOneToManyCompositorDelegate(compositor);
//	}
	
	
	// ================================================
	// UTILITY METHODS
	// ================================================
	public String toString()
	{
//		return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
		return ReflectionToStringBuilder.toString(this, ToStringStyleBuilder.toStringStyle);
	}
	public int hashCode()
	{
		HashCodeBuilder builder = new HashCodeBuilder();
	    builder.append(this.getResourceIdentifier());
	    return builder.toHashCode();		
	}
	public boolean equals(Object obj)
	{
		if (obj == null)
		{
			return false;
		}
		if (obj == this)
		{
			return true;
		}
		if (obj.getClass() != getClass())
		{
			return false;
		}
		ManyToOneCompositePart<CompositorType> that = (ManyToOneCompositePart<CompositorType>)obj;
		EqualsBuilder builder = new EqualsBuilder();
	    builder.append(this.getResourceIdentifier(), that.getResourceIdentifier());
		return builder.isEquals();
	}





	
}